﻿using System;
using System.Collections.Generic;
using System.Text;

namespace csharpcore7_ch3_Interface_Example4
{
    class InterfaceExample4
    {
        static void Main()
        {
            RichTextBox r = new RichTextBox();
            r.Undo();                   //RichTextBox.Undo
            ((IUndoable)r).Undo();      //RichTextBox.Undo
            //((TextBox)r).Undo();        //显式实现时语法错误，Undo() 不可访问。
            ((TextBox)r).Undo();        //TextBox.Undo
        }
    }
    public interface IUndoable { void Undo(); }

    public class TextBox : IUndoable
    {
        //显式实现接口中的方法
        //void IUndoable.Undo() => Console.WriteLine("TextBox.Undo");

        //隐式实现接口中的方法
        public void Undo() => Console.WriteLine("TextBox.Undo");
    }


    public class RichTextBox : TextBox,IUndoable
    {
        public  void Undo() => Console.WriteLine("RichTextBox.Undo");
    }
}
